package com.qf.shop.common.core.exception;

import com.qf.shop.common.core.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ShopExceptionHandler {

    // 系统异常：系统的bug--》系统繁忙，请稍后再试
    @ExceptionHandler(Exception.class)
    public R systemException(Exception e) {
        log.error("系统异常", e);
        return R.error("系统繁忙，请稍后再试");
    }

    // 业务异常：程序中手动抛出就是告诉用户的，比如：账号被锁定
    @ExceptionHandler(ShopException.class)
    public R business(ShopException e) {
        log.error("业务异常", e.getMsg());
        return R.error(e.getMsg());
    }
}
